#!/bin/bash -x

kata_coco_top_dir="$HOME/workspace/CoCo/"

kata_containers_repo_url="https://gitee.com/hanliyang-kata-coco/kata-containers.git"
kata_containers_repo_branch="3.13.0-hygon"
kata_containers_repo_dir="${kata_coco_top_dir}/kata-containers"

if [ ! -e ${kata_containers_repo_dir} ]; then
  git clone ${kata_containers_repo_url} \
    -b ${kata_containers_repo_branch} \
    ${kata_containers_repo_dir}
fi

build_kata_runtime_deps () {
  echo "Install kata shim & runtime dependencies"
  sudo apt install -y make gcc
}

build_kata_runtime_deps

build_install_kata_runtime () {
  echo "Build and Install kata shim & runtime"

  pushd ${kata_containers_repo_dir}/src/runtime
  make PREFIX="/opt/kata" &&
    sudo -E "PATH=$PATH" make install DESTDIR=/opt/kata PREFIX="/"
  popd # .../src/runtime
}

build_install_kata_runtime
